from django.forms import DateTimeInput, TimeInput

from bootstrap_datepicker_plus import TimePickerInput


class MyTimePickerInput(TimePickerInput):
    template_name = 'basicinfo/widgets/my-time-picker.html'


class BootstrapDateTimePickerInput(DateTimeInput):
    template_name = 'basicinfo/widgets/bootstrap_datetimepicker.html'

    def get_context(self, name, value, attrs):
        datetimepicker_id = 'datetimepicker_{name}'.format(name=name)
        if attrs is None:
            attrs = dict()
        attrs['data-target'] = '#{id}'.format(id=datetimepicker_id)
        attrs['class'] = 'form-control datetimepicker-input'
        context = super().get_context(name, value, attrs)
        context['widget']['datetimepicker_id'] = datetimepicker_id
        return context


class BootstrapTimePickerInput(TimeInput):
    template_name = 'basicinfo/widgets/bootstrap_timepicker.html'

    def get_context(self, name, value, attrs):
        timepicker_id = 'timepicker_{name}'.format(name=name)
        if attrs is None:
            attrs = dict()
        attrs['data-target'] = '#{id}'.format(id=timepicker_id)
        attrs['class'] = 'form-control datetimepicker-input'
        context = super().get_context(name, value, attrs)
        context['widget']['timepicker_id'] = timepicker_id
        print(context['widget'])
        return context
